package br.ufla.pgcc.oomeasures.plugin.popup.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;

import br.ufla.pgcc.oomeasures.plugin.views.BarChartView;
import br.ufla.pgcc.oomeasures.plugin.views.ChartView;
import br.ufla.pgcc.oomeasures.plugin.views.PieChartView;
import br.ufla.pgcc.oomeasures.plugin.views.SampleView;


public class Measure implements IObjectActionDelegate {

	private Shell shell;
	
	/**
	 * Constructor for Action1.
	 */
	public Measure() {
		super();
	}

	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	 */
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();
	}

	/**
	 * @see IActionDelegate#run(IAction)
	 */
	public void run(IAction action) {
		ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
		SampleView view = (SampleView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SampleView.ID);
		view.showSelection(selection);
		ChartView chartView = (ChartView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(ChartView.ID);
		BarChartView barChartView = (BarChartView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(BarChartView.ID);
		PieChartView pieChartView = (PieChartView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(PieChartView.ID);//RODRIGO
		
		if (chartView != null) {
			chartView.showChart(view.getItemMeasured());
		}
		
		if (barChartView != null){
			barChartView.showChart(view.getItemMeasured());
		}
		
		if (pieChartView != null) {
			pieChartView.showPieChart(view.getItemMeasured());
		}
		
		
	}

	/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection) {
		
	}

	public Shell getShell() {
		return shell;
	}

	public void setShell(Shell shell) {
		this.shell = shell;
	}
	
	

}
